using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_LevelMapTracePanel : UIBaseNode
    {
        #region Template Generate,don't modify

        protected class UIB_UIN_LevelMapTracePanel
        {
            #region ObjectBinding Generate

            public ExButton btnTrace { protected set; get; }
            public ExButton btnStopTrace { protected set; get; }
            public ExText title { protected set; get; }
            public ExText des { protected set; get; }

            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<ExButton>("btnTrace", out var __tbv0);
                btnTrace = __tbv0;
                __binding.TryGetVariableValue<ExButton>("btnStopTrace", out var __tbv1);
                btnStopTrace = __tbv1;
                __binding.TryGetVariableValue<ExText>("title", out var __tbv2);
                title = __tbv2;
                __binding.TryGetVariableValue<ExText>("des", out var __tbv3);
                des = __tbv3;
            }

            #endregion ObjectBinding Generate
        }

        #endregion Template Generate,don't modify

        #region properties

        protected UIB_UIN_LevelMapTracePanel ui { get; set; }

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_LevelMapTracePanel();
            ui.InitBinding(csObjBind);
        }

        protected override void OnInit()
        {
            ui.btnStopTrace.AddClickEvent(OnBtnStopTrace);
            ui.btnTrace.AddClickEvent(OnBtnTrace);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        private void OnBtnTrace()
        {
            if (belongWindow is not UILevelMap uiLevelMap) return;
            uiLevelMap.DoTraceEntity(_data.entityId).Forget();
        }

        private void OnBtnStopTrace()
        {
            if (belongWindow is not UILevelMap uiLevelMap) return;
            uiLevelMap.CancelTraceEntity().Forget();
            ui.btnStopTrace.SetActive(false);
            ui.btnTrace.SetActive(true);
        }

        protected override void OnDispose()
        {
        }

        #region methonds

        public void Refresh(IMapSymbolData data)
        {
            _data = data;
            var tracingEntity = GameplayAreaManager.Instance.curSceneArea?.GetTrackingEntity();
            var tracingEntityId = tracingEntity.id;
            ui.btnStopTrace.SetActive(data.entityId == tracingEntityId);
            ui.btnTrace.SetActive(!ui.btnStopTrace.gameObject.activeSelf);
            ui.title.text = data.config.Name;
            ui.des.text = data.config.Describe;
        }

        #endregion methonds

        #region fields

        private IMapSymbolData _data;

        #endregion
    }
}